package com.shiwaixiangcun.monitor.repository;

import com.rabbit.spring.data.repository.GenericJpaRepository;
import com.shiwaixiangcun.monitor.domain.WorkOrder;
import com.shiwaixiangcun.monitor.domain.WorkOrderCategory;
import com.shiwaixiangcun.monitor.enums.WorkOrderStatus;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.Date;
import java.util.List;

/**
 * Created by Administrator on 2017-11-23.
 */
public interface WorkOrderRepository extends GenericJpaRepository<WorkOrder, Long> {

    @Query("select max(number) from WorkOrder where companyId =:organizationId")
    String findNumberByCompanyId(@Param("organizationId") Long organizationId);


    @Query("select w.category from WorkOrder w where w.status = 'Accepted' group by w.category")
    List<WorkOrderCategory> getUsedCategory();

    @Query("from WorkOrder w where w.category =:category and w.createTime < :date and w.status = :status")
    List<WorkOrder> getNeedSetTimeOutWorkOrderIds(@Param("category") WorkOrderCategory category, @Param("date") Date date, @Param("status") WorkOrderStatus status);

    @Query("select count(id) from WorkOrder")
    Integer getWorkOrderToFigure();
}
